<!-- 引用编辑器 -->
<link rel="stylesheet" href="/static/kindeditor/themes/default/default.css" />
<script src="/static/kindeditor/kindeditor-all.js"></script>
<script src="/static/kindeditor/lang/zh-CN.js"></script>

<style type="text/css">
	.ke-container{
		width: 100% !important;
	}
</style>

<div class="layui-container">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md8 content detail">
        <div class="fly-panel detail-box">
          <h1>{$post.title}</h1>
          <div class="fly-detail-info">
            <!-- <span class="layui-badge">审核中</span> -->
            <span class="layui-badge layui-bg-green fly-detail-column">{$post.cate.name}</span>
            
            
            {if condition="$post.accept > 0"}
                <span class="layui-badge" style="background-color: #5FB878;">已结</span>
            {else /}
                <span class="layui-badge" style="background-color: #999;">未结</span>
            {/if}
            {if condition="$post.state == 1"}
            <span class="layui-badge layui-bg-black">置顶</span>
            {elseif condition="$post.state == 2"}
            <span class="layui-badge layui-bg-red">热门</span>
            {elseif condition="$post.state == 3"}
            <span class="layui-badge layui-bg-orange">精华</span>
            {/if}
            <div class="fly-admin-box" data-id="123">
                {if condition="$post.userid == $userid"}
                    <span class="layui-btn layui-btn-xs jie-admin del" data-id="{$post.id}" type="del">删除</span>
                {/if}

                {if condition="$post.userid != $userid"}
				    {if condition="$collect == 1"}
                        <a href="#" class="layui-btn layui-btn-xs jie-admin layui-bg-red delshou" data-id="{$post.id}">取消收藏</a>
					{elseif condition="$collect == 0"}
					    <span class="layui-btn layui-btn-xs jie-admin collection" data-id="{$post.id}">收藏</span>
					{/if}
                    <!-- <span class="layui-btn layui-btn-xs jie-admin" type="set" field="stick" rank="0" style="background-color:#ccc;">取消置顶</span> -->
                {/if}
              <!-- <span class="layui-btn layui-btn-xs jie-admin" type="set" field="status" rank="1">加精</span>  -->
              <!-- <span class="layui-btn layui-btn-xs jie-admin" type="set" field="status" rank="0" style="background-color:#ccc;">取消加精</span> -->
            </div>
            <span class="fly-list-nums"> 
              <a href="#comment"><i class="iconfont" title="回答">&#xe60c;</i> {$post.comment_count}</a>
              <i class="iconfont" title="人气">&#xe60b;</i> {$VisitCount}
            </span>
          </div>
          <div class="detail-about">
            <a class="fly-avatar" href="{:url('home/user/index',['userid' => $post.userid])}">
              <img src="{$post.user.avatar_cdn}" alt="贤心">
            </a>
            <div class="fly-detail-user">
              <a href="{:url('home/user/index',['userid' => $post.userid])}" class="fly-link">
                <cite>{$post.user.nickname}</cite>
                <i class="iconfont icon-renzheng" title="认证信息：{$post.user.nickname}"></i>
                <i class="layui-badge fly-badge-vip">VIP {$post.user.vip}</i>
              </a>
              <span>{$post.createtime}</span>
            </div>
            <div class="detail-hits" id="LAY_jieAdmin" data-id="123">
              <span style="padding-right: 10px; color: #FF7200">悬赏：{$post.point}积分</span>
              {if condition="$post.userid == $userid"}
                <span class="layui-btn layui-btn-xs jie-admin" type="edit"><a href="{:url('home/post/edit',['postid' => $post.id])}">编辑此贴</a></span>
              {/if}
            </div>
          </div>
          <div class="detail-body photos">
            {$post.content}
          </div>
        </div>
		
		<!-- 回复区域 -->
        <div class="fly-panel detail-box" id="flyReply">
          <fieldset class="layui-elem-field layui-field-title" style="text-align: center;">
            <legend>回帖</legend>
          </fieldset>
  
          <ul class="jieda" id="jieda">
			  
            {if condition="$CommentList"}
             
                {:CommentHtml($CommentList,$post,$LoginUser)}
				
            {else /}
                <!-- 无数据时 -->
                <li class="fly-none">消灭零回复</li>
            {/if}
			
            <!-- 无数据时 -->
            <!-- <li class="fly-none">消灭零回复</li> -->
          </ul>
          
           {if condition="$LoginUser && $post.accept == null"}
			  <div id="reply" style="font-size: 22px;margin-bottom: 5px;"></div>
			  <div class="layui-form layui-form-pane">
				<form action="{:url('home/comment/add')}" method="post">
				  <div class="layui-form-item layui-form-text">
					<a name="comment"></a>
					<div class="layui-input-block">
					  <textarea name="content" id="content" style="height: 300px;width:100%;"></textarea>
					  <!-- <textarea id="L_content" name="content" required lay-verify="required" placeholder="请输入内容"  class="layui-textarea fly-editor" style="height: 150px;"></textarea> -->
					</div>
				  </div>
				  <div class="layui-form-item">
					<input type="hidden" name="postid" value="{$post.id}">
					<input type="hidden" name="pid" value="0">
					<button class="layui-btn" lay-submit>提交回复</button>
				  </div>
				</form>
			  </div>
			{/if}
        </div>
      </div>
      <div class="layui-col-md4">
		  
		  <div class="fly-panel fly-rank fly-rank-reply" id="LAY_replyRank">
		      <h3 class="fly-panel-title">回贴周榜</h3>
		      <dl>
		          <!--<i class="layui-icon fly-loading">&#xe63d;</i>-->
		  		{foreach $WeekList as $item}
		          <dd>
		              <a href="user/home.html">
		                  <img
		                      src="{$item.user.avatar}"><cite>{$item.user.nickname}</cite><i>{$item['userid']}次回答</i>
		              </a>
		          </dd>
		          {/foreach}
		      </dl>
		  </div>
  
          <!-- 无数据时 -->
          <!--
          <div class="fly-none">没有相关数据</div>
          -->
  
        <div class="fly-panel" style="padding: 20px 0; text-align: center;">
          <img src="/static/home/images/weixin.jpg" style="max-width: 100%;" alt="layui">
          <p style="position: relative; color: #666;">微信扫码关注 layui 公众号</p>
        </div>
  
      </div>
    </div>
  </div>
  <script type="text/javascript">
    var editor;
	KindEditor.ready(function(K) {
		editor = K.create('textarea[name="content"]');
	})
  	layui.use(['layer'],function(){
		var $ = layui.jquery,
		layer = layui.layer
		
		// 删除评论功能
		$('.delcom').click(function(){
			let comid = $(this).data('comid')
			console.log(comid)
			
			// 发起ajax请求
			$.ajax({
				type:'post',
				url:`{:url('home/comment/delcom')}`,
				data:{
					comid
				},
				dataType:'json',
				success:function(res){
					if(res.code === 1)
					{
						layer.msg(res.msg,{icon: 1},function(){
							 location.reload();
						})
					}else{
						layer.msg(res.msg,{icon: 5})
					}
				}
			})
		})
		
		// 回复
		$('.reply').click(function(){
		  let pid = $(this).data('pid')
	
		  $('input[name="pid"]').val(pid)
	
		  let nickname = $(this).data('nickname')
	
		  let reply = '回复@'+nickname
	
		  $('#reply').html(reply)
	
		  editor.focus()
	
		})
		
		// 点赞
		$('.jieda-zan').click(function(){
			// 评论id
			let comid = $(this).data('id')
			
			$.ajax({
				type:'post',
				url:`{:url('home/comment/like')}`,
				data:{
				  comid
				},
				dataType:'json',
				success:function(res)
				{
				  if(res.code === 1)
				  {
					layer.msg(res.msg,{icon: 1},function(){
						 location.reload();
					})
				  }else{
					layer.msg(res.msg,{icon: 5})
				  }
				}
			})
		})
		
		// 如果需要异步评论
		// $('#btn').click(function(){
		//   设置同步
		//   editor.sync()
	
		//   let content = $('#content').val()
		//   console.log(content)
	
		//   return false
		// })
		
		// 采纳
		$('.accept').click(function(){
		  /* 
			1、获取评论id => 传给后台
			2、帖子id => 获取评论id => 后台查询
		  */
	
		  let comid = $(this).data('comid')
	
		  $.ajax({
			type:'post',
			url:`{:url('home/comment/accept')}`,
			data:{
			  comid
			},
			dataType:'json',
			success:function(res)
			{
			  if(res.code === 1)
			  {
				layer.msg(res.msg,{icon: 1},function(){
				  location.reload();
				})
			  }else{
				layer.msg(res.msg,{icon: 5})
			  }
			}
		  })
	
		})
		
		// 删除帖子
		$('.del').click(function(){
			var postid = $(this).data('id')
			
			layer.confirm('确定删除帖子？',{icon:3,title:'提示'},function(index){
				
				// 发起请求
				$.ajax({
				  type:'post',
				  url:`{:url('home/post/del')}`,
				  data:{
					postid
				  },
				  dataType:'json',
				  success:function(res)
				  {
					if(res.code === 1)
					{
					  layer.msg('删除成功',{icon: 1},function(index){
						location.href = res.url
					  })
					}else{
					  layer.msg(res.msg,{icon: 5})
					}
				  }
				})
				
				layer.close(index)
			})
			
		})
		
		// 收藏帖子
		$('.collection').click(function(){
			var postid = $(this).data('id')
			
			layer.confirm('确定收藏帖子？',{icon:3},function(index){
				
				// 发起请求
				$.ajax({
				  type:'post',
				  url:`{:url('home/post/collection')}`,
				  data:{
					postid
				  },
				  dataType:'json',
				  success:function(res)
				  {
					if(res.code === 1)
					{
					  layer.msg('收藏成功',{icon: 1},function(index){
						location.href = res.url
					  })
					}else{
					  layer.msg(res.msg,{icon: 5},function(){
						location.href = res.url
					  })
					}
				  }
				})
				
				layer.close(index)
			})
		})
		
		// 个人主页取消收藏帖子
		$('.delshou').click(function(){
			var collectid = $(this).data('id')
			
			layer.confirm('确定取消收藏帖子？',{icon:3},function(index){
				
				// 发起请求
				$.ajax({
				  type:'post',
				  url:`{:url('home/post/delcollect')}`,
				  data:{
					collectid
				  },
				  dataType:'json',
				  success:function(res)
				  {
					if(res.code === 1)
					{
					  layer.msg('取消收藏成功',{icon: 1},function(index){
						location.href = res.url
					  })
					}else{
					  layer.msg(res.msg,{icon: 5},function(){
						location.href = res.url
					  })
					}
				  }
				})
				
				layer.close(index)
			})
		})
	})
  </script>